﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using cart.service;
using cart.model;

namespace cart.web
{
    public partial class checkout : System.Web.UI.Page
    {
        int orderID = 0;
        protected void Page_Load(object sender, EventArgs e)
        {
            orderID = System.Convert.ToInt32(this.Request.QueryString["orderID"]);
            if (0 == orderID)
            {
                //this.Response.Write("<script type=text/javascript>alert('请先登录！')</script> ");
                this.Response.Redirect("Default.aspx");
            }
            if (!this.IsPostBack)
            {
                postService ps = new postService();
                ArrayList alProvince = new ArrayList();
                alProvince = ps.getProvince();
                foreach (postModel pm in alProvince)
                {
                    this.ddlProvince.Items.Add(new ListItem(pm.postName.Trim(), pm.postTypeId.Trim()));
                }
                this.ddlCity.Items.Add("请选择----");
                this.ddlProvince.DataBind();
            }
        }

        protected void ddlProvince_SelectedIndexChanged(object sender, EventArgs e)
        {
            //this.Response.Write(this.ddlProvince.SelectedValue);
            postService ps = new postService();
            ArrayList alCity = new ArrayList();
            alCity = ps.getCityByProvince(this.ddlProvince.SelectedValue);

            this.ddlCity.Items.Clear();

            foreach (postModel pm in alCity)
            {
                this.ddlCity.Items.Add(new ListItem(pm.postName.Trim(), pm.postTypeMasterId.Trim()));
            }

        }

        protected void lbPay_Click(object sender, EventArgs e)
        {
            orderModel om = new orderModel();
            orderServiec os = new orderServiec();
            om.username = this.tbUserName.Text.Trim();
            om.userAddr = this.ddlProvince.SelectedItem.Text.Trim() + this.ddlCity.SelectedItem.Text.Trim() + this.tbAddr.Text.Trim();
            om.zip = this.tbZip.Text.Trim();
            om.phone = this.tbPhone.Text.Trim();
            om.postType = this.ddlPostType.SelectedItem.Text.Trim();
            //this.Response.Write(orderID+"<br>"+ om.username + "<br>" + om.userAddr + "<br>" + om.zip + "<br>" + om.phone + "<br>" + om.postType);
            om.orderID = orderID;
            os.updateOrderByOrderID(om);
            this.Response.Redirect("pay.aspx?orderID=" + om.orderID);
        }
    }
}
